package hu;

import java.util.*;

public class student_hu {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] ss = sc.nextLine().split(",");
        int m = Integer.parseInt(ss[0]);
        int n = Integer.parseInt(ss[1]);
        char[][] student = new char[m][n];
        for (int i = 0; i < m; i++) {
            String[] str = sc.nextLine().split(",");
            for (int j = 0; j < n; j++) {
                student[i][j] = str[j].charAt(0);
            }
        }

        /**
         * 模拟
         */
        int res = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if(student[i][j] == 'M'){
                    res = Math.max(res, dfs(i, j, student));
                }
            }
        }
        System.out.println(res);
    }
    public static int dfs(int i, int j, char[][] student){
        int a = 0, b = 0, c = 0, d = 0;
        int row = i, col = j;
        while(row < student.length && student[row][j] == 'M'){
            row++;
            a++;
        }
        row = i;
        col = j;
        while(col < student[0].length && student[i][col] == 'M'){
            col++;
            b++;
        }
        row = i;
        col = j;
        while(row < student.length && col < student[0].length && student[row][col] == 'M'){
            col++;
            row++;
            c++;
        }
        row = i;
        col = j;
        while(row < student.length && col >= 0 && student[row][col] == 'M'){
            col--;
            row++;
            c++;
        }
        return Math.max(a, Math.max(b, Math.max(c, d)));
    }
}
